package com.yuexunit.operationman.nbsy.module.BeforeAnesthesiaVisit.ui;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.BeforeAnesthesiaVisit.BeforeAnesthesiaVisitContracts;
import com.yuexunit.operationman.nbsy.module.BeforeAnesthesiaVisit.bean.BeforeAnesthesiaBean;
import com.yuexunit.operationman.nbsy.module.BeforeAnesthesiaVisit.model.impl.BeforeAnesthesiaDetailModel;
import com.yuexunit.operationman.nbsy.module.BeforeAnesthesiaVisit.presenter.IBeforeAnesthesiaDetailPresenter;
import com.yuexunit.operationman.nbsy.module.BeforeAnesthesiaVisit.presenter.impl.BeforeAnesthesiaDetailPresenter;
import com.yuexunit.operationman.nbsy.module.BeforeAnesthesiaVisit.ui.view.IBeforeAnesthesiaDetailView;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;

import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/5/4 0004.
 */

public class Act_BeforeAnesthesiaMain extends BaseKJActivity implements IBeforeAnesthesiaDetailView{

    @Bind(R.id.titlebar_tv_title)
    TextView titlebarTvTitle;
    @Bind(R.id.beforeanesthesiamain_pic)
    ImageView beforeanesthesiamainPic;
    @Bind(R.id.beforeanesthesiamain_name)
    TextView beforeanesthesiamainName;
    @Bind(R.id.beforeanesthesiamain_age)
    TextView beforeanesthesiamainAge;
    @Bind(R.id.beforeanesthesiamain_sex)
    TextView beforeanesthesiamainSex;
    @Bind(R.id.beforeanesthesiamain_hight)
    TextView beforeanesthesiamainHight;
    @Bind(R.id.beforeanesthesiamain_weight)
    TextView beforeanesthesiamainWeight;
    @Bind(R.id.beforeanesthesiamain_position)
    TextView beforeanesthesiamainPosition;
    @Bind(R.id.beforeanesthesiamain_visitno)
    TextView beforeanesthesiamainVisitno;
    @Bind(R.id.beforeanesthesiamain_bed)
    TextView beforeanesthesiamainBed;
    @Bind(R.id.beforeanesthesiamain_way)
    TextView beforeanesthesiamainWay;
    @Bind(R.id.beforeanesthesiamain_operation)
    TextView beforeanesthesiamainOperation;
    @Bind(R.id.beforeanesthesiamain_other)
    TextView beforeanesthesiamainOther;
    @Bind(R.id.beforeanesthesiamain_suit)
    TextView beforeanesthesiamainSuit;

    IBeforeAnesthesiaDetailPresenter presenter;

    LoadingDialog loadingDialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_beforeanesthesiamain);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        setTitle();
        loadingDialog = new LoadingDialog(this);
        presenter = new BeforeAnesthesiaDetailPresenter(this,new BeforeAnesthesiaDetailModel());
    }

    @Override
    public void onResume(){
        super.onResume();
        Map<String, String> params = new HashMap<>();
        params.put("operationNo", PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_OPERATION_ID)+"");
        presenter.getBeforeAnesthesiaDate(params);
    }

    private void setTitle() {
        titlebarTvTitle.setText("麻醉前访视单");
    }


    @OnClick({R.id.titlebar_img_back, R.id.beforeanesthesiamain_ll_01, R.id.beforeanesthesiamain_ll_02,
            R.id.beforeanesthesiamain_ll_03, R.id.beforeanesthesiamain_ll_04, R.id.beforeanesthesiamain_ll_05,
            R.id.beforeanesthesiamain_ll_06, R.id.beforeanesthesiamain_ll_07})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.titlebar_img_back:
                finish();
                break;
            case R.id.beforeanesthesiamain_ll_01:
                startActivity(new Intent(aty, Act_BeforeAnesthesiaSign.class));
                break;
            case R.id.beforeanesthesiamain_ll_02:
                startActivity(new Intent(aty, Act_BeforeAnesthesiaState.class));
                break;
            case R.id.beforeanesthesiamain_ll_03:
                startActivity(new Intent(aty, Act_BeforeAnesthesiaNumber.class));
                break;
            case R.id.beforeanesthesiamain_ll_04:
                startActivity(new Intent(aty, Act_BeforeAnesthesiaEvaluate.class));
                break;
            case R.id.beforeanesthesiamain_ll_05:
                startActivity(new Intent(aty, Act_BeforeAnesthesiaAnesthesia.class));
                break;
            case R.id.beforeanesthesiamain_ll_06:
                startActivity(new Intent(aty, Act_BeforeAnesthesiaSignature.class));
                break;
            case R.id.beforeanesthesiamain_ll_07:
                startActivity(new Intent(aty, Act_BeforeAnesthesiaPreview.class));
                break;
        }
    }

    @Override
    public void getBeforeAnesthesiaDate(BeforeAnesthesiaBean beforeAnesthesiaBean) {
        if(beforeAnesthesiaBean.getCode() == 200)
        {
            AppConfig.BEFOREANSETHESIA =beforeAnesthesiaBean;
            beforeanesthesiamainName.setText(AppConfig.BEFOREANSETHESIA.getObject().getVisit().getPatientName());
            beforeanesthesiamainAge.setText(AppConfig.BEFOREANSETHESIA.getObject().getVisit().getPatientAge());
            if(AppConfig.BEFOREANSETHESIA.getObject().getVisit().getPatientSex().equals("1")) {
                beforeanesthesiamainSex.setText("男");
            }else if(AppConfig.BEFOREANSETHESIA.getObject().getVisit().getPatientSex().equals("2"))
            {
                beforeanesthesiamainSex.setText("女");
            }
            else {
                beforeanesthesiamainSex.setText("不详");
            }
            beforeanesthesiamainHight.setText(AppConfig.BEFOREANSETHESIA.getObject().getVisit().getPatientHeight());
            beforeanesthesiamainWeight.setText(AppConfig.BEFOREANSETHESIA.getObject().getVisit().getPatientWeight());
            beforeanesthesiamainPosition.setText(AppConfig.BEFOREANSETHESIA.getObject().getVisit().getDepartment());
            beforeanesthesiamainVisitno.setText(AppConfig.BEFOREANSETHESIA.getObject().getVisit().getInHospitalNo());
            beforeanesthesiamainBed.setText(AppConfig.BEFOREANSETHESIA.getObject().getVisit().getPatientBed());
            beforeanesthesiamainWay.setText("拟行手术方式:"+AppConfig.BEFOREANSETHESIA.getObject().getVisit().getOperationWay());
            beforeanesthesiamainOperation.setText(AppConfig.BEFOREANSETHESIA.getObject().getVisit().getPreOperation());
            beforeanesthesiamainOther.setText(AppConfig.BEFOREANSETHESIA.getObject().getVisit().getOtherDesc());
            beforeanesthesiamainSuit.setText(AppConfig.BEFOREANSETHESIA.getObject().getVisit().getComplain());

            if(AppConfig.BEFOREANSETHESIA.getObject().getVisitItems() == null)
            {
                AppConfig.BEFOREANSETHESIA.getObject().setVisitItems(BeforeAnesthesiaVisitContracts.beforeAnesthesiaItemListEntities(this));
            }
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }
}
